//
//  ShoppingOrderRequest.m
//  EasyToo
//
//  Created by zhengzhe on 13-9-15.
//
//

#import "ShoppingOrderRequest.h"
#import "OrderInfo.h"

@implementation ShoppingOrderRequest


- (id)initWithOrderArray:(NSMutableArray*)array Tel:(NSString*)telNum Delegate:(id<ServerCommunicationDelegate>)delegate
{
    self = [super init];
    if (self) {
        
        self.requestName = @"ShoppingOrderRequest";
        self.delegate = delegate;
        
        self.url = PROTOCOL_ORDER_URL;
        
        [self.headerJsonDict setObject:@"012002" forKey:@"TranCode"];
        
        NSMutableArray *orderDictArray = [[[NSMutableArray alloc] init] autorelease];

        float totalPrice = 0;
        
        for (int i = 0; i < [array count]; i++)
        {
            OrderInfo *order = [array objectAtIndex:i];
            NSMutableDictionary *orderDict = [order toDictionary];
            [orderDictArray addObject:orderDict];
            
            totalPrice += order.price * (float)order.num;
        }
        
        [self.headerJsonDict setObject:[NSNumber numberWithFloat:totalPrice*100]  forKey:@"TxAmt"];
        
        [self.bodyJsonDict setObject:orderDictArray forKey:@"orders"];
        [self.bodyJsonDict setObject:telNum forKey:@"receTel"];
        [self.bodyJsonDict setObject:telNum forKey:@"orderTel"];
        [self.bodyJsonDict setObject:[NSNumber numberWithFloat:totalPrice] forKey:@"totalamount"];
        
        [self buildJsonRequest];
    }
    return self;
}

@end
